﻿/*----------------------------------------------------------------------------------------
*
*  Copyright 2019, Gao Hai Hui, <fromzeropoint@126.com>.  All rights reserved.
*  https://gitee.com/helloworldghh/xoskit.git
*  Use of this source code is governed by a MIT license
*  that can be found in the License file.
*
----------------------------------------------------------------------------------------*/
#include "../import/head.h"
#include "../global/head.h"
#include "protocol_impl.h"
#include "bzip2_impl.h"
#include "zlib_impl.h"
#include "lzma_impl.h"
#include "compress_mgr.h"

namespace xos_compress
{

    //////////////////////////////////////////////////////////////////////////////////////////////////////////
    // 

    compress_mgr::compress_mgr()
    {
        g_pSysData->m_pMgr = this;
    }

    compress_mgr::~compress_mgr()
    {
        if( g_pSysData )
        {
            g_pSysData->term();
            delete g_pSysData;
            g_pSysData = 0;
        }
    }

    //////////////////////////////////////////////////////////////////////////////////////////////////////////
    // 

	// 
	// create objects
	// 
	int compress_mgr::create( enumObjType enumType, void ** ppv )
	{
		int ret = 0;

		switch( enumType )
		{
        case enumObjType::OBJ_PROTOCOL:
			{
                protocol_impl * p = protocol_impl::get_item_from_pool( true );
				p->init();
				*ppv = p;
			}
			break;
		case enumObjType::OBJ_BZIP2:
			{
				bzip2_impl * p = bzip2_impl::get_item_from_pool( true );
				p->init();
				*ppv = p;
			}
			break;
		case enumObjType::OBJ_LZMA:
			{
				lzma_impl * p = lzma_impl::get_item_from_pool( true );
				p->init();
				*ppv = p;
			}
			break;
		case enumObjType::OBJ_ZLIB:
			{
                zlib_impl * p = zlib_impl::get_item_from_pool( true );
				p->init();
				*ppv = p;
			}
			break;
        default:
            {
                ret = 1;
            }
            break;
		}

		return ret;
	}

    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    // 

    int compress_mgr::put_back_to_pool( T * pT, bool bLock )
    {
        int ret = 0;
        delete this;
        return ret;
    }

    int compress_mgr::init()
    {
        int ret = 0;
        return ret;
    }

    int compress_mgr::term()
    {
        int ret = 0;
        return ret;
    }

} // xos_compress
